<template>
	<view class="mainContent">
		<view class="twoSecond">
			<view class="left">
				<view><text>体检机构：</text><input type="text" v-model="medicalName" :disabled="status == 2"></view>
				<p class="flex">体检时间：
					<picker mode="date" :start="start" :end="end"  :disabled="status == 2"  @change="bindDateChange">
						<view class="date">{{medicalTime || '选择体检时间'}}</view>
					</picker> 
				</p>
			</view>
			<!-- <view class="right" v-if="status != 2">
				<view class="save" @click="seveAdd(1)">保存</view>
				<view class="saveSure" @click="seveAdd(2)">确认存档</view>
			</view> -->
		</view>
		<view class="uploadBox"> 
			<u-upload  ref="uUpload" :header="header" :form-data="{type:12}" :action="action" :file-list="imgUrls"  :deletable="false" @on-uploaded="uploaded"></u-upload>
		</view>
		<u-modal v-model="showModal" :show-cancel-button="true" @confirm="Modalconfirm" :content="showContent"></u-modal>
	</view>
</template>

<script>
	import http from '@/common/http/interface.js'
	export default {
		data (){
			const currentDate = this.getDate({
				format: true
			})
			return {
				start: '',
				end: currentDate,
				medicalTime:'',
				userName:'',
				imgUrls: [],
				action: http.config.baseUrl+'/File/multipleFiles',
				header:{
					"Token": localStorage.token
				},
				editId:'',
				memberdialog: false,
				showModal:false,
				showContent:'',
				medicalName:'',
				status:'', //存档状态
			}
		},
		onLoad(options) {
			if(options.id){
				this.editId = options.id
				this.status = options.status
				if(options.status == 2){
					uni.setNavigationBarTitle({
						title: '查看体检报告'
					})
				}
				this.$api.userRisksfindId(options.id).then((res)=>{
					this.medicalName = res.data.result.medicalName
					this.medicalTime = res.data.result.medicalTime
					this.userId = res.data.result.userId
					this.userName = res.data.result.realName
					this.imgUrls = res.data.result.imgUrls.map((a)=>{
						return {url:a}
					})
				})
			}
		},
		methods:{
			// 获取当前时间
			getDate(type) {
			   const date = new Date();
			   let year = date.getFullYear();
			   let month = date.getMonth() + 1;
			   let day = date.getDate();
			  
			   if (type === 'start') {
				year = year - 60;
			   } else if (type === 'end') {
				year = year + 2;
			   }
			   month = month > 9 ? month : '0' + month;;
			   day = day > 9 ? day : '0' + day;
			   return `${year}-${month}-${day}`;
			},
			// 日期
			bindDateChange(e) {  //日期选择
				this.medicalTime = e.target.value;
			},
			hidememberdialog(){
				this.memberdialog = false
			},

			uploaded(lists, name){
				this.imgUrls = lists.map((a)=>{
					if(a.file){
						a.url = a.response.result[0]
					}
					return a
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.mainContent {
		width: 750upx;
		min-height: calc(100vh - 44px);
		background-color: #FFFFFF;
		.twoSecond {
			width: 750upx;
			height: 176upx;		
			background: #F5FFFB;
			// box-shadow: 0upx 4upx 30upx 0upx rgba(222, 222, 222, 0.3);
			display: flex;
			position: fixed;
			top: 44px;
			align-items: center;
			padding: 0 24upx;
			box-sizing: border-box;
			z-index: 200;
			.left {
				flex: 1;
				width: 702upx;
				view {
					display: flex;
					align-items: center;
					text {
						color: #333333;
						font-size: 30upx;
					}				
					input {
						width: 319upx;
						height: 46upx;
						padding-left: 10upx;
						border: 1upx solid #E4E4E4;
						border-radius: 6upx;
						display: inline-block;
						margin: 10upx 0;
					}
				}
			}
			.right {
				view {
					width: 174upx;
					height: 46upx;
					background: #FF8F23;
					border-radius: 8upx;
					color: #FFFFFF;
					font-size: 30upx;
					text-align: center;
					line-height: 46upx;
				}
				.saveSure {
					background-color: #38CB97;
					margin-top: 21upx;
				}
			}
		}
		.uploadBox {
			margin-top: 200rpx;
			width: 750upx;
			padding: 0 60upx;
			box-sizing: border-box;
			display: flex;
			flex-wrap: wrap;
			.u-upload{
				width: 100%;
				display: flex;
				justify-content: space-between;
				/deep/ .u-list-item {
					width: 266upx !important;
					height: 350upx !important;
					background: #EFEFEF;
					border-radius: 10upx;
					position: relative;
				}
			}
		}
	}
	.flex{
		display: flex;
		font-size: 30rpx;
		.date{
			width: 334upx;
			height: 50upx;
			padding-left: 10upx;
			border: 1upx solid #E4E4E4;
			border-radius: 6upx;
		}
	}
</style>
